<template>
  <div class="container">
    <a-spin size="large" :tip="tip">
      <div class="container"></div>
    </a-spin>
  </div>
</template>
<script lang="ts" setup>
import { useStore } from "vuex";
import { useRouter, useRoute } from "vue-router";
import qs from "qs";
import { SYS_TOKEN } from "@/utils/global-constant";
import LocalCache from "@/utils/cache";
import { login, getUserInfo } from "@/service/modules/login/login";

const tip = "加载中...";
const store = useStore();
const router = useRouter();
const route = useRoute();
//模拟接口菜单数据
const menuList = [
  {
    spyCode: "zbb_02",
    title: "值班表管理",
  },
  {
    spyCode: "zbb_03",
    title: "值班记录管理",
  },
];
//系统初始化
doLogin();
// 登录-获取用户信息-获取菜单
async function doLogin() {
  const query = qs.parse(decodeURIComponent(route.fullPath.split("?")[1]));
  const { orgCode = "scsslytzx", token = "FE47175B2E3B4929A9031B9C0B6B68C0" } =
    query;
  const params = {
    orgCode,
    token,
  };
  const loginResult = await login(params);
  if (loginResult?.code === 0) {
    LocalCache.setCache(SYS_TOKEN, loginResult?.token);
    const userInfo = await getUserInfo();
    if (userInfo?.code === 0) {
      LocalCache.setCache("userInfo", userInfo?.data);
    }
    getMenu();
    router.push({
      path: "/home",
    });
  }
}
// 获取菜单信息
function getMenu() {
  if (!(window as any).__POWERED_BY_QIANKUN__) {
    store.dispatch("addRoutes/actionMenu", menuList);
  }
}
</script>

<style scoped lang="less">
.container {
  width: 100%;
  height: 100vh;
}
</style>
